from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.text import PP_ALIGN

# 新建PPT
prs = Presentation()

# 封面
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Pickleball Player Pose Detection"
slide.placeholders[1].text = "姓名/学号/日期\n指导老师"

# 目录
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "目录"
content = "\n".join([
    "1. 项目背景与意义",
    "2. 项目流程与数据集",
    "3. 创新点1：自动化数据集同步",
    "4. 创新点2：关键点标注可视化",
    "5. 创新点3：自定义训练与权重管理",
    "6. 实验结果与对比",
    "7. 总结与展望",
    "8. 参考文献"
])
slide.placeholders[1].text = content

# 项目背景与意义
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "项目背景与意义"
slide.placeholders[1].text = (
    "• 匹克球运动员姿态估计的应用价值\n"
    "• 姿态估计在体育分析、健康监测等领域的意义\n"
    "• YOLO系列算法简介"
)

# 项目流程与数据集
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "项目流程与数据集"
slide.placeholders[1].text = (
    "• 数据采集与处理流程\n"
    "• 数据集结构说明（图片、标注、同步）\n"
    "• 主要用到的脚本和工具"
)
# 插入一张数据集样例图片
slide.shapes.add_picture("./dataset/images/train/frame_045780.jpg", Inches(5), Inches(2), width=Inches(4))

# 创新点1
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "创新点1：自动化数据集同步"
slide.placeholders[1].text = (
    "• 理论依据：数据一致性对模型训练的重要性\n"
    "• sync_dataset.py实现思路\n"
    "• 同步前后数据统计对比"
)
# 可插入一张数据同步前后对比的图片（如有）
# slide.shapes.add_picture("your_sync_compare_image.jpg", Inches(5), Inches(2), width=Inches(4))

# 创新点2
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "创新点2：关键点标注可视化"
slide.placeholders[1].text = (
    "• 理论依据：标注质量对姿态估计的影响\n"
    "• visualize_pose_label.py实现思路\n"
    "• 可视化前后对比图片"
)
# 插入关键点可视化图片
slide.shapes.add_picture("./frame_045780_vis.jpg", Inches(5), Inches(2), width=Inches(4))

# 创新点3
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "创新点3：自定义训练与权重管理"
slide.placeholders[1].text = (
    "• 理论依据：实验可控性与复现性\n"
    "• train_ultralytics.py自定义权重加载（yolo11n-pose.pt）\n"
    "• 训练流程图"
)
# 可插入一张训练流程图（如有）

# 实验结果与对比
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "实验结果与对比"
slide.placeholders[1].text = (
    "• loss/mAP曲线\n"
    "• 混淆矩阵\n"
    "• 预测与标注可视化\n"
    "• 关键点漂移修正前后mAP提升"
)
# 插入loss/mAP曲线
slide.shapes.add_picture("./runs/train/yolov8n_pose/results.png", Inches(0.5), Inches(2), width=Inches(4))
# 插入混淆矩阵
slide.shapes.add_picture("./runs/train/yolov8n_pose/confusion_matrix.png", Inches(5), Inches(2), width=Inches(4))

# 预测与标注可视化
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "预测与标注可视化"
slide.placeholders[1].text = (
    "• 左：模型预测结果\n"
    "• 右：真实标注"
)
slide.shapes.add_picture("./runs/train/yolov8n_pose/val_batch0_pred.jpg", Inches(0.5), Inches(2), width=Inches(4))
slide.shapes.add_picture("./runs/train/yolov8n_pose/val_batch0_labels.jpg", Inches(5), Inches(2), width=Inches(4))

# 关键点相关曲线
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "关键点检测性能曲线"
slide.placeholders[1].text = (
    "• Pose Precision/Recall/F1/PR曲线"
)
slide.shapes.add_picture("./runs/train/yolov8n_pose/PoseP_curve.png", Inches(0.5), Inches(2), width=Inches(2.5))
slide.shapes.add_picture("./runs/train/yolov8n_pose/PoseR_curve.png", Inches(3.2), Inches(2), width=Inches(2.5))
slide.shapes.add_picture("./runs/train/yolov8n_pose/PoseF1_curve.png", Inches(6), Inches(2), width=Inches(2.5))

# 总结与展望
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "总结与展望"
slide.placeholders[1].text = (
    "• 创新点带来的实际提升\n"
    "• 项目不足与后续改进方向"
)

# 参考文献
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "参考文献"
slide.placeholders[1].text = (
    "1. Ultralytics YOLO官方文档\n"
    "2. 相关论文与开源项目\n"
    "3. 其他参考资料"
)

prs.save("Pickleball_Pose_Project.pptx")
print("高质量PPT已自动生成：Pickleball_Pose_Project.pptx")
